using System;
using System.Collections.Generic;
using TouchSmart.Widgets;

namespace TouchSmart.Animations
{
    public abstract class Animation
    {
        protected readonly List<Widget> _widgets;

        protected Animation()
        {
            this._widgets = new List<Widget>();
            IsCompleted = true;
        }

        public bool IsCompleted { get; protected set; }

        public void Animate(int delta)
        {
            AnimateInternal(delta);
            IsCompleted = GetIsCompleted();
        }

        protected virtual bool GetIsCompleted()
        {
            return false;
        }

        protected abstract void AnimateInternal(int delta);

        protected abstract void Reset();

        public Animation AnimateOn(Widget widget)
        {
            this._widgets.Add(widget);
            return this;
        }

        public void Start()
        {
            if(IsCompleted == false) return;

            Reset();
            var animator = Locator.GetService<IAnimator>();
            animator.QueueAnimation(this);
            IsCompleted = false;
        }

        public void Stop()
        {
            IsCompleted = true;
        }
    }
}